package com.hmall.util;

/**
 * 封装ThreadLocal工具
 */
public class ThreadLocalUtils {

    private static final ThreadLocal<Long> tl=new ThreadLocal<>();

    /**
     * 向ThreadLocal中保存userId
     * @param userId 用户id
     */
    public static void setUserId(Long userId){
        tl.set(userId);
    }

    /**
     * 从ThreadLocal中获取userId
     */
    public static Long getUserId(){
        return tl.get();
    }

    /**
     * 从ThreadLocal中移除userId
     */
    public static void removeUserId(){
        tl.remove();
    }
}
